// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
// import "babel-polyfill";

import VueResource from "vue-resource";
// import ElementUI from '../element-ui/src'
import ElementUI from "element-ui";
// import NProgress from "vue-nprogress";
import Vuex from "vuex";
import Vue2Filters from "vue2-filters";
import Utils from "./utils/utils";

import router from "./router";
import "./utils/prototype";
import App from "./App";
import store from "./store";
import * as Constants from "./utils/constants";
import "./directives";
import "./filters";
import VueLazyload from "vue-lazyload";

Vue.use(VueResource)
Vue.use(ElementUI)
Vue.use(Vuex)
// Vue.use(NProgress)
Vue.use(Vue2Filters)
Vue.use(Utils)
Vue.use(VueLazyload,{
  loading: '/static/loading.gif',
  preLoad: 1,
  attempt: 3
})
Vue.config.productionTip = false

Vue.http.options.emulateJSON = true;
Vue.http.interceptors.push(function (request, next) {
  request.headers.set('X-Requested-With', 'XMLHttpRequest');
  if (request.params) {
    request.params.t = new Date().getTime();
  }
  next(function (response) {
    let data = response.body;
    if (data.responseCode === Constants.NOT_LOGIN_ERROR) {
      window.location.href = Constants.LOGIN_URL;
      response.ok = false;
      return response;
    }

    if (data.responseCode !== Constants.OPERATE_SUCCESS) {
      ElementUI.Message.warning(data.message);
      response.ok = false;
      response.status = 403;
      return response;
    }
  });
});

// const nprogress = new NProgress({parent: '.nprogress-container', showSpinner: false})

new Vue({
  el: '#app',
  router,
  store,
  // nprogress,
  template: '<App/>',
  components: {App}
})
